﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using cart.service;
using cart.model;

namespace cart.web
{
    public partial class pay : System.Web.UI.Page
    {
        orderModel om;
        protected void Page_Load(object sender, EventArgs e)
        {
            int orderID = Convert.ToInt32(this.Request.QueryString["orderID"]);
            if (0 == orderID)
            {
                this.Response.Redirect("shopCart.aspx");
            }

            orderServiec os = new orderServiec();
            om =  os.getOrderByID(orderID);

            this.lbUserName.Text = om.userID.Trim();
            this.lbTotle.Text = om.totle.ToString().Trim();
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //this.Response.Write(this.txtTotle.Text.Trim());
            try
            {
                double totle =Convert.ToDouble(this.txtTotle.Text.Trim());
                if (totle == om.totle)
                {
                    //this.Response.Write(om.totle);
                    this.lblSuccess.Text = "支付成功!";
                    om.paymentState = 1;
                    orderServiec os = new orderServiec();
                    orderModel omd = new orderModel();
                    os.updateOrderByOrderID(om);
                    omd = os.getOrderByID(om.orderID);
                    this.lblOrder.Text = "订单明细：";
                    ArrayList alOrder = new ArrayList();
                    alOrder.Add(omd);
                    this.gvOrderDetails.DataSource = alOrder;
                    this.gvOrderDetails.DataBind();


                    this.lblOrderItems.Text = "商品明细：";
                    ArrayList alOrderItems = new ArrayList();
                    orderItemsService ois = new orderItemsService();
                    alOrderItems = ois.getOrderItemsByOrderID(omd.orderID);
                    this.gvOrderItmes.DataSource = alOrderItems;
                    this.gvOrderItmes.DataBind();
                }
                else
                {
                    this.Response.Write("<script>alert('您支付的金额不正确！');</script>");
                }
            }
            catch
            {
                this.Response.Write("<script>alert('请您正确支付！');</script>");
            }
        }
    }
}
